
<script>
	import Vue from 'vue'
	// #ifdef APP-PLUS
	import APPUpdate from "@/js_sdk/APPUpdate";
	import utils from '@/utils/utils'
	import store from '@/store/index';
	// #endif
	export default {
		onLaunch: async function() {
			// #ifdef APP-PLUS
			APPUpdate();
			// #endif
			
			// 长时间未登录清除缓存
			this.$util.clearExpiration();
			/* uniCloud.callFunction({
				name: 'bak',
				success(e) {
					console.log(e);
				},
			}) */
				
			uni.getSystemInfo({
				success: e=> {
					this.initSize(e);
				}
			})
			
			const handlePushClick = function (message) {
			  const payload = JSON.parse(message.payload);
			  // if (payload.type !== '2') {
			  //   uni.navigateTo({
			  //     url: `/pages/information/informationDetails?id=${payload.msgId}`,
			  //   });
			  // }
			};
			// #ifdef APP-PLUS
			const platform = uni.getSystemInfoSync().platform;
			if (platform == "ios") {
				//导入ios UIApplication
	//             var UIApplication = plus.ios.import('UIApplication');
	//             var app = UIApplication.sharedApplication();
	            //获取应用图标的数量
	            // var oldNum = app.applicationIconBadgeNumber();
	            // var newNum = oldNum - 1;
	            //设置应用图标的数量
	            plus.runtime.setBadgeNumber(0);
	            //导入个推原生类
	            var GeTuiSdk = plus.ios.importClass('GeTuiSdk');
	            GeTuiSdk.setBadge(0);
			// }else{
			//  plus.runtime.setBadgeNumber(0);  
			}
			
			// 监听接收透传消息事件
			plus.push.addEventListener('receive', function(msg){  
				  console.log(msg)
				  if (msg.type == "receive") // 这里判断触发的来源，否则一直推送。  
				  	{
				  		if (platform == 'ios') {
				  			// console.log(msg.payload)
				  			plus.push.createMessage(
				  				msg.content,
				  				//本地创建通知payload只能传string，否则无法成功传递（为null）
				  				JSON.stringify(msg.payload), {
				  					cover: false,
				  					title: msg.payload.title,
				  				});
				  		}
				  	}
			    // 有消息推送，创建本地通知栏消息
			    // plus.push.createMessage( msg.content, msg.payload, {}); 
			}, false);
			// 监听系统通知栏消息点击事件  
			// plus.push.addEventListener('click', function(msg){  
			// 	console.log(msg)
			//     // 跳转到指定也页面  
			// }, false);
			// #endif
			// this.initLogin();
			// if(this.$store.state.tabbar.length===4&& uni.getStorageSync('userType')== 1 ) {
			// 	this.$store.commit('changeFootBar',{icon: 'iconqianbao2',text: "会员钱包"});
			// }else if(this.$store.state.tabbar.length===5&& uni.getStorageSync('userType')== 0 ) {
			// 	this.$store.commit('removeFootBar');
			// }
			
			
			if(this.$util.getToken()) {
				this.$util.getIdentity();
				this.$util.getDictDataAll();//获取字典所有数据
			}
			// 设置是否首次进入
			let speadFlag = true;
			// #ifdef H5
			if(this.$util.getUrlCode("share")) {
				speadFlag = false;
			}
			// #endif
			this.$util.setInitSpeadFlag(speadFlag);
			this.$util.getRecordLogin();
		},
		methods: {
			refreshToken(){
				this.$util.setToken('');
				const data = {
					grant_type: 'refresh_token',
					refreshToken: this.$util.getRefreshToken(),
				}
				return this.$http.refreshToken(data)
			},
			//登录状态
			// async initLogin(){
			// 	const token = uni.getStorageSync('uniIdToken');
			// 	if(token){
			// 		this.$store.commit('setToken', {
			// 			token
			// 		});
			// 	}
			// },
			/**
			 * 存储设备信息 参考colorUI
			 * @param {Object} 
			 */
			initSize(e){
				const systemInfo = e;
				let navigationBarHeight;
				let custom = {};
				// #ifndef MP
				custom = {height: 36,width: 88};
				navigationBarHeight = 44;
				// #endif
				// #ifdef MP-WEIXIN
				custom = wx.getMenuButtonBoundingClientRect();
				navigationBarHeight = custom.bottom + custom.top - e.statusBarHeight * 2;
				// #endif	
				systemInfo.custom = custom;
				systemInfo.navigationBarHeight = navigationBarHeight;
				Vue.prototype.systemInfo = systemInfo;
			},
			
		},
		onShow() {
			// if(this.$util.getToken()) {
			// 	this.$util.getDictDataAll();//获取字典所有数据
			// }
		},
		onHide() {
			// 刷新有效时间
			this.$util.setExpiration();
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
	/* @import "./static/style/iconfont-weapp-icon.css"; */
	@import "./static/style/iconfont.css";
	@import './components/gaoyia-parse/parse.css';
	
	/* #ifdef H5 */
	/* #endif */
	/* 多选框样式 */
	>>>uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
	    border-color:#d1d1d1;
	}
	>>>.tui-checkbox .uni-checkbox-input {
		width: 30rpx;
		height:30rpx;
		border-radius: 8rpx !important;
	}
	
	>>>.tui-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
		background-image:linear-gradient(to right,#F69E97,#EA655E) !important;
		width: 32rpx !important;
		height: 32rpx !important;
		border: none;
	}
	
	>>>.tui-checkbox .uni-checkbox-input.uni-checkbox-input-checked::before {
		width: 30rpx !important;
		height: 30rpx !important;
		line-height: 30rpx;
		text-align: center;
		font-size: 20rpx;
		color: #fff;
		background: transparent;
		transform: translate(-50%, -50%);
		-webkit-transform: translate(-50%, -50%);
	}
	uni-toast{
		z-index: 99999;
	}
	
</style>
